using System;
using System.CodeDom;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace CodeDom
{
  internal class CheckboxFieldPropertyGenerator : TemplateFieldGenerator
  {
    public CheckboxFieldPropertyGenerator(TemplateField field)
      : base(field)
    {
    }

    public override void AddValueConversionStatements(CodeExpression itemReference, CodeMemberMethod method)
    {
      CodeExpression getValue = CreateFieldValueExpression(itemReference);
      CodeBinaryOperatorExpression comparison = new CodeBinaryOperatorExpression(getValue, CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression("1"));
      CodeStatement returnStatement = new CodeMethodReturnStatement(comparison);
      method.Statements.Add(returnStatement);

    }

    public override CodeTypeReference GetFieldType()
    {
      return new CodeTypeReference("Boolean");
    }
  }
}